package com.spider.admin.controller;

import com.spider.admin.exception.SpiderException;
import com.spider.admin.http.entity.PageResult;
import com.spider.admin.service.agent.AgentOptionService;
import com.spider.admin.service.agent.AgentSettingService;
import com.spider.admin.store.primary.model.AgentOption;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/agent")
public class AgentOptionsController {
    @Autowired
    private AgentOptionService agentOptionService;
    @Autowired
    private AgentSettingService agentSettingService;

    @GetMapping("/list")
    public PageResult<AgentOption> queryAgentOptionList(@RequestParam(required = false) Integer currentPage, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) String section) throws SpiderException {
        return agentOptionService.queryAgentOptionList(currentPage, pageSize, section);

    }

    @PostMapping("/save")
    public int saveAgentOption(@RequestBody AgentOption agentOption) throws SpiderException {
        return agentOptionService.saveAgentOption(agentOption);
    }

    @DeleteMapping("/remove/{pid}")
    public int deleteAgentOption(@PathVariable String pid) throws SpiderException {
        agentSettingService.deleteWithOptionPid(pid);
        return agentOptionService.deleteAgentOption(pid);
    }
}
